package com.orange.core.validator;

import cn.hutool.core.util.StrUtil;
import com.orange.core.util.Constants;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class MobilePhoneValidator implements ConstraintValidator<IsMobilePhone, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StrUtil.isBlank(value)) {
            return false;
        }
        Pattern pattern = Pattern.compile(Constants.MOBILE_PHONE_RGX);
        return pattern.matcher(value).matches();
    }
}
